***************
* This script produces Table 2
* Author: Daniel Kopp
***************

clear
clear matrix
clear mata
set more off	
set maxvar 8000


****	
* We start with descriptive statistics on earnings and age
****	

use "Misc_files/earnings_age_unobserved.dta"

label var alter "\quad Age"
label var versich_verdienst_no0_adj "\quad Insured monthly earnings adj."

* Fulltime men
quietly estpost sum   versich_verdienst_no0_adj   alter   if geschlecht==0 & fulltime==1
eststo fulltime_men
* Parttime men 
quietly estpost sum   versich_verdienst_no0_adj   alter   if geschlecht==0 & fulltime==0
eststo parttime_men
* Difference men
quietly estpost ttest  versich_verdienst_no0_adj  alter   if geschlecht==0, by(fulltime)
eststo diff_men
* Fulltime Women
quietly estpost sum   versich_verdienst_no0_adj   alter   if geschlecht==1 & fulltime==1
eststo fulltime_women
* Parttime Women 
quietly estpost sum   versich_verdienst_no0_adj   alter   if geschlecht==1 & fulltime==0
eststo parttime_women
* Difference Women
quietly estpost ttest  versich_verdienst_no0_adj   alter  if geschlecht==1, by(fulltime)
eststo diff_women

gen title3_long = 0 
label var title3_long "\textbf{A. Jobseeker characteristics}"		// we need this to circumvent the stata limit on the length of variable names
clonevar title3 = title3_long		

esttab fulltime_women parttime_women diff_women fulltime_men parttime_men diff_men using "$results_part_time\table_2.tex", replace ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.2gc)) b(star pattern(0 0 1 0 0 1) fmt(%9.2gc))") noobs label  frag  ///
		mgroups("\textbf{Women}" "\textbf{Men}", pattern(1 0 0 1 0 0) span  prefix(\multicolumn{@span}{c}{) suffix(} )  erepeat(\cmidrule(lr){@span}))  ///
		collabels(none) ///
		mtitle("Full-time" "Part-time" "Difference" "Full-time" "Part-time" "Difference" )  ///
		keep(  title3 alter versich_verdienst_no0_adj  ) ///	
		order( title3 alter versich_verdienst_no0_adj  ) ///	
		title(Candidate characteristics by Full-time/Part-time and gender \label{tab:DescrCandFullParttimeShort}) ///
		addnote("Source: Seco Jobroom data") ///
		substitute("\textbf{A. Jobseeker characteristics}&            &            &                     &            &            &                     \\" "\multicolumn{4}{l}{\textbf{A. Jobseeker characteristics}}  & \multicolumn{3}{c}{ } \\ ") 

****	
* Load and append estimates of past unemployment 
****	

estimates use "${save_path}\unem_before_full_men"
estimates store unem_before_full_men

estimates use "${save_path}\unem_before_part_men"
estimates store unem_before_part_men	
		
estimates use "${save_path}\unem_before_diff_men"
estimates store unem_before_diff_men	

estimates use "${save_path}\unem_before_full_women"
estimates store unem_before_full_women

estimates use "${save_path}\unem_before_part_women"
estimates store unem_before_part_women	
		
estimates use "${save_path}\unem_before_diff_women"
estimates store unem_before_diff_women			
			
* Show the table
esttab unem_before_full_women unem_before_part_women unem_before_diff_women unem_before_full_men unem_before_part_men unem_before_diff_men, ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.3fc)) b(star pattern(0 0 1 0 0 1) fmt(%9.3fc))")  label  collabels(none) varlabels(`e(labels)')  ///
		mgroups("\textbf{Women}" "\textbf{Men}",pattern(1 0 0 1 0 0)  span prefix(\multicolumn{@span}{c}{) suffix(})) ///
		coeflabels(unenmpl_bef01Mar2017 "\quad Unemployed before March 1, 2017") ///
		mtitle("fulltime" "parttime" "difference" "fulltime" "parttime" "difference") ///
		title(Share jobseekers unemployed before March 1, 2017) 
* Append the table				
esttab unem_before_full_women unem_before_part_women unem_before_diff_women unem_before_full_men unem_before_part_men unem_before_diff_men using "$results_part_time\table_2.tex", append ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.3fc)) b(star pattern(0 0 1 0 0 1) fmt(%9.3fc))")   label nonumber noobs collabels(none) varlabels(`e(labels)') nolines frag 	 ///
		coeflabels(unenmpl_bef01Mar2017 "\quad Unemployed before March 1, 2017") ///		
		substitute("&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{} &\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{} \\" "")		
		
		
****		
* Load and append estimates regarding job search behavior on Job-Room 
****

estimates use "${save_path}\jobroom_usage_full_men"
estimates store	jobroom_usage_full_men
		
estimates use "${save_path}\jobroom_usage_part_men"
estimates store	jobroom_usage_part_men

estimates use "${save_path}\jobroom_usage_diff_men"
estimates store	jobroom_usage_diff_men		

estimates use "${save_path}\jobroom_usage_full_women"
estimates store	jobroom_usage_full_women
		
estimates use "${save_path}\jobroom_usage_part_women"
estimates store	jobroom_usage_part_women

estimates use "${save_path}\jobroom_usage_diff_women"
estimates store	jobroom_usage_diff_women	


gen  title2_long = 1
label var title2_long "\textbf{B. Jobseeker search behavior}"
clonevar title2 = title2_long

esttab  jobroom_usage_full_women jobroom_usage_part_women jobroom_usage_diff_women jobroom_usage_full_men jobroom_usage_part_men jobroom_usage_diff_men, ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.3fc)) b(star pattern(0 0 1 0 0 1) fmt(%9.3fc))")  label  collabels(none) varlabels(`e(labels)')  ///
		keep(title2 search_jobroom) ///
		order(title2 search_jobroom) ///		
		mgroups("\textbf{Women}" "\textbf{Men}", pattern(1 0 0 1 0 0)  span prefix(\multicolumn{@span}{c}{) suffix(})) ///
		coeflabels(search_jobroom "\quad Share active on Job-Room" ) ///
		mtitle("fulltime" "parttime" "difference" "fulltime" "parttime" "difference") ///
		title(Share jobseekers and number of searches on Job-Room) 	
esttab jobroom_usage_full_women jobroom_usage_part_women jobroom_usage_diff_women jobroom_usage_full_men jobroom_usage_part_men jobroom_usage_diff_men using "$results_part_time\table_2.tex", append ///
		keep(title2 search_jobroom) ///
		order(title2 search_jobroom) ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.3fc)) b(star pattern(0 0 1 0 0 1) fmt(%9.3fc))") nolines label nonumber noobs collabels(none) varlabels(`e(labels)')  frag 	///	
		coeflabels(search_jobroom "\quad Share active on Job-Room" ) ///		
		substitute("&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{} &\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{} \\" "")		
	
esttab  jobroom_usage_full_women jobroom_usage_part_women jobroom_usage_diff_women jobroom_usage_full_men jobroom_usage_part_men jobroom_usage_diff_men, ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.1fc)) b(star pattern(0 0 1 0 0 1) fmt(%9.1fc))")  label  collabels(none) varlabels(`e(labels)')  ///
		keep(clicks_stes click_stes_all) ///
		mgroups("\textbf{Women}" "\textbf{Men}",pattern(1 0 0 1 0 0)  span prefix(\multicolumn{@span}{c}{) suffix(})) ///
		coeflabels(clicks_stes "\quad  \# ad views in 1st month (if active)" click_stes_all "\quad  \# ad views in 1st month") ///
		mtitle("fulltime" "parttime" "difference" "fulltime" "parttime" "difference") ///
		title(Share jobseekers and number of searches on Job-Room) 	
esttab jobroom_usage_full_women jobroom_usage_part_women jobroom_usage_diff_women jobroom_usage_full_men jobroom_usage_part_men jobroom_usage_diff_men using "$results_part_time\table_2.tex", append ///
		order(clicks_stes click_stes_all) ///
		cells("mean(pattern(1 1 0 1 1 0) fmt(%9.1fc)) b(star pattern(0 0 1 0 0 1) fmt(%9.1fc))") nolines label nonumber noobs collabels(none) varlabels(`e(labels)')  frag 	///	
		keep(clicks_stes click_stes_all) ///
		coeflabels(clicks_stes "\quad  \# ad views in 1st month (if active)" click_stes_all "\quad  \# ad views in 1st month") ///		
		substitute("&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{} &\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{} \\" "")		
	

****
* Add key figures from the Work Volume Statistics for the year 2017:
****

clear
set obs 10
gen 	geschlecht = 0 if _n<=5
replace geschlecht = 1 if _n>5

* Absences from work (in % of normal hours)
gen 	absences1 = 0.042 if geschlecht==0
replace absences1 = 0.053 if geschlecht==1
gen 	absences0 = 0.054 if geschlecht==0
replace absences0 = 0.059 if geschlecht==1
label var absences1 "\quad Absences (in \% of normal hours)"

* Overtime (in % of normal hours)
gen 	overtime1 = 0.024 if geschlecht==0
replace overtime1 = 0.015 if geschlecht==1
gen 	overtime0 = 0.036 if geschlecht==0
replace overtime0 = 0.030 if geschlecht==1
label var overtime1 "\quad Overtime (in \% of normal hours)"

* Actual hours (in % of normal hours)
gen 	actual1 = 0.982 if geschlecht==0
replace actual1 = 0.961 if geschlecht==1
gen 	actual0 = 0.982 if geschlecht==0
replace actual0 = 0.972 if geschlecht==1
label var actual1 "\quad Actual hours (in \% of normal hours)"

* Net turnover rate
gen 	turnover1 = 0.115 if geschlecht==0
replace turnover1 = 0.163 if geschlecht==1
gen 	turnover0 = 0.116 if geschlecht==0
replace turnover0 = 0.102 if geschlecht==1
label var turnover1 "\quad Turnover rate"


******
* Add key figures from the Swiss Adult Education Survey (MZB) for the year 2016 (the survey is conducted every 5 years)
******

* Participtaion in non-formal professional training
gen 	proftraining1 = 0.685 if geschlecht==0
replace proftraining1 = 0.672 if geschlecht==1
gen 	proftraining0 = 0.612 if geschlecht==0
replace proftraining0 = 0.593 if geschlecht==1
label var proftraining1 "\quad Participation in professional training"

* Participation in non-formal extra-professional training
gen 	extratraining1 = 0.225 if geschlecht==0
replace extratraining1 = 0.317 if geschlecht==1
gen 	extratraining0 = 0.257 if geschlecht==0
replace extratraining0 = 0.343 if geschlecht==1
label var extratraining1 "\quad Participation in extra-prof. training"


****
* Gen Table
****

eststo clear
quietly estpost sum  absences1 overtime1 actual1 turnover1  proftraining1 extratraining1 if geschlecht==0
estimates store full_men

quietly estpost sum  absences0 overtime0 actual0 turnover0  proftraining0 extratraining0 if geschlecht==0
estimates store part_men

quietly estpost sum  absences1 overtime1 actual1 turnover1  proftraining1 extratraining1 if geschlecht==1
estimates store full_women

quietly estpost sum  absences0 overtime0 actual0 turnover0  proftraining0 extratraining0 if geschlecht==1
estimates store part_women

gen empty = 1
quietly estpost sum empty
estimates store empty


esttab full_women part_women empty full_men part_men empty , ///
			cells("mean(fmt(3))")  label ///
			rename( absences0 absences1 overtime0 overtime1 actual0 actual1 turnover0 turnover1 proftraining0 proftraining1 extratraining0 extratraining1) ///
			collabels(none) noobs nonumbers nolines ///
			keep("\textbf{C. Worker characteristics}" absences1 overtime1 actual1 proftraining1 extratraining1 turnover1) ///	
			order("\textbf{C. Worker characteristics}"  absences1 overtime1 actual1 proftraining1 extratraining1 turnover1) ///
			coeflabels(absences1 "\quad Absences (\% of normal hours)" overtime1 "\quad Overtime (\% of normal hours)" actual1 "\quad Actual hours (\% of normal hours)" turnover1 "\quad Turnover rate" proftraining1  "\quad Participation in prof. training" extratraining1 "\quad Participation in extra-prof. training" ) 

esttab full_women part_women empty full_men part_men empty using "$results_part_time\table_2.tex", append ///
			cells("mean(fmt(3))")  label frag ///
			rename( absences0 absences1 overtime0 overtime1 actual0 actual1 turnover0 turnover1 proftraining0 proftraining1 extratraining0 extratraining1) ///
			collabels(none) noobs nonumbers nolines ///
			keep("\textbf{C. Worker characteristics}" absences1 overtime1 actual1 proftraining1 extratraining1 turnover1) ///	
			order("\textbf{C. Worker characteristics}"  absences1 overtime1 actual1 proftraining1 extratraining1 turnover1) ///
			coeflabels(absences1 "\quad Absences (\% of normal hours)" overtime1 "\quad Overtime (\% of normal hours)" actual1 "\quad Actual hours (\% of normal hours)" turnover1 "\quad Turnover rate" proftraining1  "\quad Participation in prof. training" extratraining1 "\quad Participation in extra-prof. training" )  ///
			substitute(" &\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}\\" "")
			

